<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>Document</title>
    <script src="https://unpkg.com/react@16/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
    <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
</head>
<body>
<div id="app"></div>
<script type="text/babel">
  class Hello extends React.Component {
    constructor () {
      super()
      this.state = { list: [], val: {} }
    }

    changeVal = (event, col) => {
      const value = event.target.value
      const { val } = this.state
      val[col] = value
      this.setState({
        val
      })
    }
    changeAdd = () => {
      const { list, val } = this.state
      list.push(<li key="{val.id}">{val.name}-{val.age}</li>)
      this.setState({
        list
      })
    }

    render () {
      const { list, val } = this.state
      return <div>
        <h1>hello,world</h1>
        id: <input value={val.id} onChange={(e) => this.changeVal(e, 'id')} type="text"/><br/>
        name: <input value={val.name} onChange={(e) => this.changeVal(e, 'name')} type="text"/><br/>
        age: <input value={val.age} onChange={(e) => this.changeVal(e, 'age')} type="text"/><br/>
        <div>
          <ul>
            {list}
          </ul>
        </div>
        <button onClick={this.changeAdd}>添加数据</button>
      </div>
    }
  }

  ReactDOM.render(<Hello/>, document.getElementById('app'))
</script>
</body>
</html>
